
export default (params) => {
  $.ajaxSetup({
    headers: {
      'authorization': 'auth'
    },
    contentType: 'application/json; charset=utf-8'
  });

  if (params.method && params.method === 'GET') {
    if (params.data) {
      let param = '';
      let obj = eval(params.data);
      for (let item in obj) {
        param += item + '=' + obj[item] + '&';
      }
      if (param && param.length > 0) {
        param = param.substr(0, param.length - 1);
      }
      params.url = params.url + '?' + param;
    }
  }
  return new Promise((resolve, reject) => {
    $.ajax({
      url: params.url,
      type: params.method,
      data: JSON.stringify(params.data),
      headers: params.headers,
      cache: params.cache,
      contentType: params.contentType,
      processData: params.processData,
      success: function (data) {
        let res = data;
        console.log(data)
        if (res.resultCode === 200 || res.resultCode === 0) {
          if (!res) {
            res = {resultData: 'success'};
          }
          resolve(res.resultData);
        } else {
          reject(res.resultMessage || 'failed');
        }
      },
      error: function (err) {
        reject(err);
      }
    });
  });
};
